package StudyCode.summary.regularexpressionsmatch;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class UsingNamedGroupsInRegularExpressions {
	public static void main(String[] args) {
		String regex = "\\b(?<areaCode>\\d{3})(?<prefix>\\d{3})(?<lineNumber>\\d{4})\\b";

		String replacementText = "(${areaCode}) ${prefix}-$3";

		String source = "1111111111, 1111111, and 1111111111";

		Pattern p = Pattern.compile(regex);

		Matcher m = p.matcher(source);

		String formattedSource = m.replaceAll(replacementText);

		System.out.println("文本: " + source);
		System.out.println("格式化后文本: " + formattedSource);
	}
}
